import 'package:flutter/material.dart';
import 'package:flutter_hplus/theme/theme.dart';

/// 表格操作栏组件
/// 包含搜索框和操作按钮
class TableActions extends StatelessWidget {
  final TextEditingController searchController;
  final Function(String) onSearch;
  final List<Widget>? leftActions;
  final List<Widget>? rightActions;
  final bool enableSearch;

  const TableActions({
    super.key,
    required this.searchController,
    required this.onSearch,
    this.leftActions,
    this.rightActions,
    this.enableSearch = true,
  });

  @override
  Widget build(BuildContext context) {
    final theme = HTheme.of(context);
    
    return Padding(
      padding: const EdgeInsets.only(bottom: 8.0),
      child: Row(
        children: [
          // 搜索框
          if (enableSearch)
            SizedBox(
              width: 300, height: 36,
              child: TextField(
                controller: searchController,
                decoration: InputDecoration(
                  hintText: '搜索',
                  prefixIcon: const Icon(Icons.search),
                  enabledBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(theme.dimens.borderRadius),
                    borderSide: BorderSide(color: theme.colors.inputBorderColor), // 未选中状态边框颜色
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(theme.dimens.borderRadius),
                    borderSide: BorderSide(color: theme.colors.info, width: 2.0), // 选中状态边框颜色
                  ),
                  isDense: true,
                  contentPadding: const EdgeInsets.symmetric(vertical: 6.0, horizontal: 8.0),
                ),
                onChanged: onSearch,
              ),
            ),
          // 左侧操作按钮
          if (leftActions != null) ...[
            const SizedBox(width: 16),
            ...leftActions!,
          ],
          const Spacer(),
          // 右侧操作按钮
          if (rightActions != null) ...[
            ...rightActions!,
          ],
        ],
      ),
    );
  }
} 